package com.chainyoung.component_tmperson.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chainyoung.common.base.BaseActivity;
import com.chainyoung.common.constant.LibConstant;
import com.chainyoung.common.di.AppComponent;
import com.chainyoung.common.utils.SPUtil;
import com.chainyoung.common.utils.ToastUtil;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.di.component.DaggerPersonActivityComponent;
import com.chainyoung.component_tmperson.di.module.PersonActivityModule;
import com.chainyoung.component_tmperson.entity.InviteFriend;
import com.chainyoung.component_tmperson.ui.mvp.contract.InviteFriendContract;
import com.chainyoung.component_tmperson.ui.mvp.presenter.InviteFriendPresenter;

import java.util.TreeMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//邀请好友页面

public class InviteFriendActivity extends BaseActivity<InviteFriendPresenter> implements InviteFriendContract.View {


    @BindView(R2.id.tv_invite_code)
    TextView tvInviteCode;
    @BindView(R2.id.tv_copy_code)
    TextView tvCopyCode;
    @BindView(R2.id.ll_1)
    LinearLayout ll1;

    @BindView(R2.id.tv_invite_link)
    TextView tvInviteLink;
    @BindView(R2.id.tv_copy_link)
    TextView tvCopyLink;
    @BindView(R2.id.ll_2)
    LinearLayout ll2;

    @BindView(R2.id.tv_invite_ad)
    TextView tvInviteAd;
    @BindView(R2.id.tv_copy_ad)
    TextView tvCopyAd;


    private ClipboardManager clipboardManager;
    private ClipData mClipData;


    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPersonActivityComponent.builder()
                .appComponent(appComponent)
                .personActivityModule(new PersonActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initUI() {
        setCurrentTitle(R.string.tmperson_invite_friend);
        clipboardManager = (ClipboardManager) mContext.getSystemService(mContext.CLIPBOARD_SERVICE);
    }

    @Override
    protected void initData() {
        TreeMap<String, Object> map = new TreeMap<>();
        map.put("token", SPUtil.getString(LibConstant.TOKEN));
        mPresenter.getInviteFriend(map);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.tmperson_activity_invite_friend;
    }

    @Override
    public void onGetInviteFriendSucces(InviteFriend data) {
        tvInviteCode.setText(data.getInvit());
        tvInviteLink.setText(data.getInvit_url());
        tvInviteAd.setText(data.getInvit_text_url());
    }

    @OnClick(R2.id.tv_copy_code)
    void copyCode() {
        String text = tvInviteCode.getText().toString();
        //创建一个新的文本clip对象
        mClipData = ClipData.newPlainText("block", text);
        //把clip对象放在剪贴板中
        clipboardManager.setPrimaryClip(mClipData);
        ToastUtil.showToast(getString(R.string.tmperson_copy_success));
    }

    @OnClick(R2.id.tv_copy_link)
    void copyLink() {
        String text = tvInviteLink.getText().toString();
        //创建一个新的文本clip对象
        mClipData = ClipData.newPlainText("block", text);
        //把clip对象放在剪贴板中
        clipboardManager.setPrimaryClip(mClipData);
        ToastUtil.showToast(getString(R.string.tmperson_copy_success));
    }

    @OnClick(R2.id.tv_copy_ad)
    void copyAd() {
        String text = tvInviteAd.getText().toString();
        //创建一个新的文本clip对象
        mClipData = ClipData.newPlainText("block", text);
        //把clip对象放在剪贴板中
        clipboardManager.setPrimaryClip(mClipData);
        ToastUtil.showToast(getString(R.string.tmperson_copy_success));
    }




}
